package is.ru.honn.rupin.data;

import java.sql.ResultSet;
import java.sql.SQLException;

import is.ru.honn.rupin.domain.Board;
import is.ru.honn.rupin.domain.User;
import org.springframework.jdbc.core.simple.ParameterizedRowMapper;

/**
 * Created with IntelliJ IDEA.
 * User: gmatt
 * Date: 20.10.2012
 * Time: 02:08
 *
 * Maps the column values to the appropriate properties of a Board instance
 */
public class BoardRowMapper implements ParameterizedRowMapper<Board> {
    /**
     * @param rs The result set to map (1 or more rows of Boards)
     * @param rowNum The number of the row to map
     * @return The appropriate Board instance
     * @throws SQLException
     */
    public Board mapRow(ResultSet rs, int rowNum) throws SQLException {
        Board board = new Board(rs.getString(1),
                                rs.getString(2));
        board.setCreated(rs.getDate(4));
        User user = new User();
        user.setUsername(rs.getString(3));
        board.setCreator(user);
        return board;
    }
}
